﻿Public Class BgUploadConfigForm

    Private _pi As ProjectItem

    Private Sub BgUploadConfigForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CenterToParent()

        _pi = MainForm.pi

        LoadData()
    End Sub

    Private Sub LoadData()
        Dim isBgHD, isBgHA, isBgDi As Boolean
        '*********************************************************
        '2009年06月10日 李吉鹏增加
        '********************************************************
        Select Case _pi.connectType
            Case 1 '直连
                isBgHD = IIf(KeyValuePairClass.GetValue(_pi.ProjectID, "BackgroundUploadHistoryData_Com").Equals("1"), True, False)
                isBgHA = IIf(KeyValuePairClass.GetValue(_pi.ProjectID, "BackgroundUploadAlarm_Com").Equals("1"), True, False)
                isBgDi = IIf(KeyValuePairClass.GetValue(_pi.ProjectID, "g_BackgroundUploadDiData_Com").Equals("1"), True, False)

            Case 0 '拨号
                isBgHD = IIf(KeyValuePairClass.GetValue(_pi.ProjectID, "BackgroundUploadHistoryData_Tel").Equals("1"), True, False)
                isBgHA = IIf(KeyValuePairClass.GetValue(_pi.ProjectID, "BackgroundUploadAlarm_Tel").Equals("1"), True, False)
                isBgDi = IIf(KeyValuePairClass.GetValue(_pi.ProjectID, "g_BackgroundUploadDiData_Tel").Equals("1"), True, False)

            Case 2 'TCP
                isBgHD = IIf(KeyValuePairClass.GetValue(_pi.ProjectID, "BackgroundUploadHistoryData_Tcp").Equals("1"), True, False)
                isBgHA = IIf(KeyValuePairClass.GetValue(_pi.ProjectID, "BackgroundUploadAlarm_Tcp").Equals("1"), True, False)
                isBgDi = IIf(KeyValuePairClass.GetValue(_pi.ProjectID, "g_BackgroundUploadDiData_Tcp").Equals("1"), True, False)

        End Select

        '****************************************************************************************************************
        rbBgHDYes.Checked = isBgHD
        rbBgHDNo.Checked = Not isBgHD
        rbBgHAYes.Checked = isBgHA
        rbBgHANo.Checked = Not isBgHA
        Me.rbDiHAYes.Checked = isBgDi
        Me.rbDiHANo.Checked = Not isBgDi
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If Save() Then
            Dim str As String = "保存配置信息成功。"
            If Not g_offline Then
                str &= vbCrLf & vbCrLf & "注意：配置将在下次连接时生效。"
            End If
            msg.Show(str)
            Me.DialogResult = Windows.Forms.DialogResult.OK
            Me.Close()
        End If
    End Sub

    Private Function Save() As Boolean
        Try

            '*********************************************************
            '2009年06月10日 李吉鹏增加
            '********************************************************
            Select Case _pi.connectType
                Case 1 '直连
                    KeyValuePairClass.SetValue(_pi.ProjectID, "BackgroundUploadHistoryData_Com", IIf(rbBgHDYes.Checked, 1, 0))
                    KeyValuePairClass.SetValue(_pi.ProjectID, "BackgroundUploadAlarm_Com", IIf(rbBgHAYes.Checked, 1, 0))

                    KeyValuePairClass.SetValue(_pi.ProjectID, "g_BackgroundUploadDiData_Com", IIf(rbDiHAYes.Checked, 1, 0))

                    g_BackgroundUploadHistoryData_Com = rbBgHDYes.Checked
                    g_BackgroundUploadAlarm_Com = rbBgHAYes.Checked

                    g_BackgroundUploadDiData_Com = rbDiHAYes.Checked
                Case 0 '拨号
                    KeyValuePairClass.SetValue(_pi.ProjectID, "BackgroundUploadHistoryData_Tel", IIf(rbBgHDYes.Checked, 1, 0))
                    KeyValuePairClass.SetValue(_pi.ProjectID, "BackgroundUploadAlarm_Tel", IIf(rbBgHAYes.Checked, 1, 0))

                    KeyValuePairClass.SetValue(_pi.ProjectID, "g_BackgroundUploadDiData_Tel", IIf(rbDiHAYes.Checked, 1, 0))

                    g_BackgroundUploadHistoryData_Tel = rbBgHDYes.Checked
                    g_BackgroundUploadAlarm_Tel = rbBgHAYes.Checked

                    g_BackgroundUploadDiData_Tel = rbDiHAYes.Checked
                Case 2 'TCP
                    KeyValuePairClass.SetValue(_pi.ProjectID, "BackgroundUploadHistoryData_Tcp", IIf(rbBgHDYes.Checked, 1, 0))
                    KeyValuePairClass.SetValue(_pi.ProjectID, "BackgroundUploadAlarm_Tcp", IIf(rbBgHAYes.Checked, 1, 0))

                    KeyValuePairClass.SetValue(_pi.ProjectID, "g_BackgroundUploadDiData_Tcp", IIf(rbDiHAYes.Checked, 1, 0))

                    g_BackgroundUploadHistoryData_Tcp = rbBgHDYes.Checked
                    g_BackgroundUploadAlarm_Tcp = rbBgHAYes.Checked

                    g_BackgroundUploadDiData_Tcp = rbDiHAYes.Checked

            End Select

            '****************************************************************************************************************

            

        Catch ex As Exception
            msg.ShowError("保存配置信息失败。")
            Return False
        End Try

        Return True
    End Function

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

End Class